﻿Type=Activity
Version=1.90
FullScreen=False
IncludeTitle=True
@EndOfDesignText@
'Activity module
Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	
	Dim Timer1 As Timer
	Type Curves (Name As String, Color As Int, Width As Float, Scale As Double, offset As Double, Draw As Boolean)
	Dim CurveVal(4, 101) As Double
	Dim ScreenX0, ScreenX1, ScreenY0, ScreenY1, ScreenW, ScreenH, Border As Int
	Dim GridX0, GridX1, GridY0, GridY1, GridYm, GridW, GridH, Div As Int
	Dim NbDivX, NbDivY As Int
	Dim ScreenCol, GridLineCol As Int
	
	Dim t, dt As Double
	Dim dx, xx, cx As Float
	Dim ii As Int
	Dim CurveI As Int								' curve index
	Dim Curve(4) As Curves
	Dim CurvesI(4) As Int
	Dim CurvesNb As Int							: CurvesNb = 3
	Dim CurvesNbDisp As Int
	Dim y1(4) As Float
	Dim y2(4) As Float
	Dim SingleShot As Boolean				: SingleShot = False
	Dim Stopped As Boolean					: Stopped = True
	Dim ScopeMode As String					: ScopeMode = "ROLL"
	Dim ScopeRolling As Boolean			: ScopeRolling = False
	Dim w(4) As Double
	Dim a(4) As Double
	Dim TimeScale(10) As Double
	Dim SignalScale(10) As Double
	Dim MSP_IDENT, MSP_STATUS,MSP_RAW_IMU  , MSP_SERVO ,MSP_MOTOR ,MSP_RC ,MSP_RAW_GPS ,MSP_COMP_GPS       ,MSP_ATTITUDE       ,MSP_ALTITUDE       ,MSP_BAT            ,MSP_RC_TUNING      ,MSP_PID            ,MSP_BOX            ,MSP_MISC           ,MSP_SET_RAW_RC     ,MSP_SET_RAW_GPS    ,MSP_SET_PID        ,MSP_SET_BOX        ,MSP_SET_RC_TUNING  ,MSP_ACC_CALIBRATION,MSP_MAG_CALIBRATION,MSP_SET_MISC       ,MSP_RESET_CONF     ,MSP_EEPROM_WRITE   ,MSP_DEBUG          
	  MSP_IDENT                =100
	  MSP_STATUS               =101
	  MSP_RAW_IMU              =102
	  MSP_SERVO                =103
	  MSP_MOTOR                =104
	  MSP_RC                   =105
	  MSP_RAW_GPS              =106
	  MSP_COMP_GPS             =107
	  MSP_ATTITUDE             =108
	  MSP_ALTITUDE             =109
	  MSP_BAT                  =110
	  MSP_RC_TUNING            =111
	  MSP_PID                  =112
	  MSP_BOX                  =113
	  MSP_MISC                 =114
	  MSP_SET_RAW_RC           =200
	  MSP_SET_RAW_GPS          =201
	  MSP_SET_PID              =202
	  MSP_SET_BOX              =203
	  MSP_SET_RC_TUNING        =204
	  MSP_ACC_CALIBRATION      =205
	  MSP_MAG_CALIBRATION      =206
	  MSP_SET_MISC             =207
	  MSP_RESET_CONF           =208
	  MSP_EEPROM_WRITE         =250
	  MSP_DEBUG                =254
	Dim stateMSP,offset,dataSize,indTX As Int
	checksum=0	
	stateMSP=0
	offset=0
	dataSize=0
	indTX=0
	Dim checksum As Byte
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Dim btnStart, btnStop, btnSingleShot As Button
	Dim pnlOcilloscope, pnlScreen, pnlGraph, pnlCursor, pnlControl As Panel
	Dim pnlCurveTools, pnlDispValues As Panel
	Dim cvsScreen, cvsGraph, cvsCursor As Canvas
	Dim rectScreen, rectGrid As Rect
	Dim spnTimeScale As Spinner
	Dim spnScale0, spnScale1, spnScale2, spnScale3 As Spinner
	Dim lblScale0, lblScale1, lblScale2, lblScale3 As Label
	Dim lblValue0, lblValue1, lblValue2, lblValue3 As Label
	Dim lblOffset0, lblOffset1, lblOffset2, lblOffset3 As Label
	Dim edtOffset0, edtOffset1, edtOffset2, edtOffset3 As EditText
	Dim rbtScopeScope, rbtScopeMEM, rbtScopeROLL As RadioButton
	Dim scvControl As ScrollView
	Dim bmpRoll As Bitmap
	Dim choselist As List 
	Dim labelcheckbox(4) As Label
	Dim checkboxtags(4) As String
	Dim vals(4) As Label
	Dim id As Int
	
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Activity.Title = ProgName & " " & ProgVersion
	choselist.Initialize
	'choselist.AddAll(Array As String ("Ax","Ay","Az","Gx","Gy","Gz","Mag x","Mag y","Mag z","Alt","Heading"))
	choselist.AddAll(Array As String ("Ax","Ay","Az","Gx","Gy","Gz","Mag x","Mag y","Mag z"))
	t = 0
	If Main.protocol=0 Then 
		Timer1.Initialize("Timer1", 75)
	Else 
		Timer1.Initialize("Timer1", 35)
	End If 	
	NbDivX = 10
	NbDivY = 8
	
	Div = Floor(80%y / NbDivY)
	'NbDivX=Floor(100%x/Div)
	xx = 0
	dx = Div / 10
	GridW = Div * NbDivX
	GridH = Div * NbDivY
	Border = 6dip
	
	ScreenY0 = 0
	ScreenH = GridH + 2 * Border
	ScreenY1 = ScreenY0 + ScreenH
	
	ScreenX0 = 0
	ScreenW = GridW + 2 * Border
	ScreenX1 = ScreenX0 + ScreenW

	GridY0 = Border
	GridY1 = GridY0 + GridH
	GridX0 = Border
	GridX1 = GridX0 + GridW
	GridYm = GridH / 2
	
	rectGrid.Initialize(0, 0, GridW, GridH)
	rectScreen.Initialize(0, 0, ScreenW, ScreenH)
	
	ScreenCol = Colors.black
	GridLineCol = Colors.Gray
	
	pnlOcilloscope.Initialize("")
	Activity.AddView(pnlOcilloscope, 0, 0, 100%x, 100%y)
	
	pnlScreen.Initialize("")
	pnlOcilloscope.AddView(pnlScreen, ScreenX0, ScreenY0, ScreenW, ScreenH)
	cvsScreen.Initialize(pnlScreen)
	
	pnlGraph.Initialize("")
	pnlOcilloscope.AddView(pnlGraph, GridX0, GridY0, GridW, GridH)
	cvsGraph.Initialize(pnlGraph)

	pnlCursor.Initialize("pnlCursor")
	pnlOcilloscope.AddView(pnlCursor, GridX0, GridY0, GridW, GridH)
	cvsCursor.Initialize(pnlCursor)
	

	
	Dim w1, w2, w3, t1, h1 As Int
	w1 = 4dip
	w2 = 0
	w3 = w1 + w2
	t1 = 4dip
	h1 = 52dip
	Activity.AddMenuItem("Start","btnStart")
	Activity.AddMenuItem("Stop","btnStop")
	Activity.AddMenuItem("Single","btnSingleShot")
	
	
	'scvControl.Initialize(480dip)
	'pnlOcilloscope.AddView(scvControl, ScreenX1, 0%y, 100%x - ScreenX1, 100%y )
	'scvControl.Panel.LoadLayout("controls")
	'scvControl.Panel.Width = scvControl.Width
	Dim cbg As ColorDrawable
	cbg.Initialize(Colors.RGB(196, 196, 255), 0)
	'scvControl.Panel.Background = cbg
	'scvControl.Color = Colors.RGB(196, 196, 255)
	
	pnlCurveTools.Initialize("")
	pnlOcilloscope.AddView(pnlCurveTools, 0, ScreenY1, 100%x, 100%y - ScreenY1)
	Dim cbg As ColorDrawable
	cbg.Initialize(Colors.RGB(0, 0, 0), 0)
	pnlCurveTools.Background = cbg
	
	pnlDispValues.Initialize("")
	pnlOcilloscope.AddView(pnlDispValues, 0, ScreenY1, 100%x, 100%y - ScreenY1)
	Dim cbg As ColorDrawable
	cbg.Initialize(Colors.RGB(255, 236, 153), 0)
	pnlDispValues.Background = cbg
	pnlDispValues.Visible = False
	
	InitCurves
	InitCalcCurves
	InitSpinners

	Dim ww As Float
	ww = pnlDispValues.Width / 4
	lblValue0.Initialize("")
	pnlDispValues.AddView(lblValue0, 0, 0, ww, pnlDispValues.Height)
	lblValue0.TextColor = Curve(0).Color
	lblValue0.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
	
	lblValue1.Initialize("")
	pnlDispValues.AddView(lblValue1, ww, 0, ww, pnlDispValues.Height)
	lblValue1.TextColor = Curve(1).Color
	lblValue1.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
	
	lblValue2.Initialize("")
	pnlDispValues.AddView(lblValue2, 2 * ww, 0, ww, pnlDispValues.Height)
	lblValue2.TextColor = Curve(2).Color
	lblValue2.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
	
	lblValue3.Initialize("")
	pnlDispValues.AddView(lblValue3, 3 * ww, 0, ww, pnlDispValues.Height)
	lblValue3.TextColor = Curve(3).Color
	lblValue3.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
	
	
	For i = 0 To 3
		Dim cbx As CheckBox
		cbx.Initialize("cbxDrawCurve")
		pnlCurveTools.AddView(cbx, 6dip + i * 100dip, 0, 60dip, 50dip)
			
		labelcheckbox(i).Initialize("labelcheckbox")
		pnlCurveTools.AddView(labelcheckbox(i), 56dip + i * 100dip, 0, 40dip, 50dip)
		
		cbx.Tag = i
		cbx.Checked = True
		labelcheckbox(i).Tag=i
		checkboxtags(i)=i
		labelcheckbox(i).Text=choselist.Get(i)
		labelcheckbox(i).Gravity=Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
		
		vals(i).Initialize("")
		Activity.AddView(vals(i),Activity.Width-60dip, 10%y+i*15%y,100dip,30dip)
		vals(i).Gravity=Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
	Next
	labelcheckbox(0).TextColor=Colors.Red
	labelcheckbox(1).TextColor=Colors.blue
	labelcheckbox(2).TextColor=Colors.Green
	labelcheckbox(3).TextColor=Colors.Magenta
	
	ScopeMode="ROLL"
End Sub

Sub Activity_Resume
	InitGrid
End Sub

Sub Activity_Pause (UserClosed As Boolean)
	btnStop_Click
	Main.return_from_cli=True
	StartActivity(Main)
 	Activity.Finish
End Sub

Sub InitGrid
	Dim i As Int
	Dim x, y As Float
	
	cvsScreen.DrawRect(rectScreen, ScreenCol, True, 1)
	For i = 0 To NbDivY
		y = GridX0 + i * Div
		cvsScreen.DrawLine(GridX0, y, GridX1, y, GridLineCol, 1dip)
	Next
	
	For i = 0 To NbDivX
		x = GridY0 + i * Div
		cvsScreen.DrawLine(x, GridY0, x, GridY1, GridLineCol, 1dip)
	Next
	pnlScreen.Invalidate

	cvsGraph.DrawRect(rectGrid, Colors.Transparent, True, 1)
	pnlGraph.Invalidate
	
	cvsCursor.DrawRect(rectGrid, Colors.Transparent, True, 1)
	pnlCursor.Invalidate
End Sub
Sub spnScale_ItemClick (Position As Int, Value As Object)
	Dim spn As Spinner
	spn = Sender
	Curve(spn.Tag).Scale = Div / Value
End Sub
Sub btnStart_Click
	Timer1.Enabled = True
	SingleShot = False
	Stopped = False
	ii = 100
	xx = -dx
	EraseCurves
	id=0
End Sub

Sub btnStop_Click
	Timer1.Enabled = False
	SingleShot = False
	Stopped = True
End Sub

Sub btnSingleShot_Click
	Timer1.Enabled = True
	SingleShot = True
	Stopped = False
	ii = -1
	xx = -dx
	EraseCurves
End Sub


Sub edtOffset_FocusChanged (HasFocus As Boolean)
	Dim edt As EditText
	Dim val As Double
	
	If HasFocus = False Then
		edt = Sender
		Curve(edt.Tag).offset = edt.Text
	End If
End Sub

Sub read16(b As Int, c As Int) As Int
	Return Bit.And(b,0xFF) + Bit.ShiftLeft(Bit.And(c,0xFF),8)
End Sub
Sub read32(b As Int, c As Int,d As Int, e As Int) As Int
	Return Bit.And(read16(b,c),0xFF) + Bit.ShiftLeft(Bit.And(read16(d,e),0xFF),16)
End Sub

Sub read8(b As Int) As Int
	Return Bit.And(b,0xFF) 
End Sub
Sub Timer1_Tick
	Dim i, j As Int
	
	t = t + dt
	xx = xx + dx
	ii = ii + 1
	If ii > 100 Then
		If SingleShot = True Then
			Timer1.Enabled = False
			SingleShot = False
			Stopped = True
			Return
		Else
			Select ScopeMode 
			Case "MEM"
				xx = 0
				ii = 0
				GetValues
				DrawCurves
			Case "SCOPE"
				EraseCurves
				xx = 0
				ii = 0
				GetValues
				DrawCurves
			Case "ROLL"
				ii = 100
				xx = 100 * dx
				For i = 0 To 3
					For j = 0 To 99
						CurveVal(i, j) = CurveVal(i, j + 1)
					Next
				Next
				ScopeRolling = True
				GetValues
				DrawCurves
			End Select
			Return
		End If
	End If
	GetValues
	DrawCurves
End Sub

Sub DrawCurves
	Dim i, j As Int
	Dim r1, r2 As Rect
	Dim x, yy1(4), yy2(4) As Float
	
	If SingleShot = False Then
		
			If ScopeRolling = True Then
				cvsGraph.DrawRect(rectGrid, Colors.Transparent, True, 1)
				For i = 0 To CurvesNb
					If Curve(i).Draw = True Then
						yy1(i) = GridYm + (-Curve(i).offset - CurveVal(i, 0)) * Curve(i).Scale
						For j = 1 To 99
							x = j * dx
							yy2(i) = GridYm + (-Curve(i).offset - CurveVal(i, j)) * Curve(i).Scale
							cvsGraph.DrawLine(x - dx, yy1(i), x, yy2(i), Curve(i).Color, Curve(i).Width)
							yy1(i) = yy2(i)				
						Next
					End If
				Next
			End If
		
	End If
	For i = 0 To CurvesNb
		If Curve(i).Draw = True Then
			y2(i) = GridYm + (-Curve(i).offset - CurveVal(i, ii)) * Curve(i).Scale
			If ii > 0 Then
				cvsGraph.DrawLine(xx - dx, y1(i), xx, y2(i), Curve(i).Color, Curve(i).Width)
			End If
			y1(i) = y2(i)
		End If
	Next
	pnlGraph.Invalidate
	DoEvents
End Sub

Sub GetValues
	If Main.connected Then
		If Main.TextReader1.Ready Then 'check if there is any data waiting to be read
			'Dim output As String
			Dim buffer(155) As Char
			Dim alt As Int	
			ret=Main.TextReader1.read(buffer,0,buffer.length)
			Dim ints(100) As Int
			Dim buff2(100) As Char
			If Main.protocol=0 Then 
				For i=0 To 23
					ints(i)=Asc(buffer(i))
					buff2(i)=buffer(i)
				Next
			Else
				Dim ints2(100) As Int
				For i=0 To ret
					ints2(i)=Asc(buffer(i))
				Next
				stateMSP=ints2(4)
					
				If stateMSP>99 Then 
					Select stateMSP
						Case MSP_RAW_IMU
		                	stateMSP = 0
		               		 For i=0 To 19
								ints(i)=ints2(i+5)
							Next
						Case MSP_ATTITUDE
				            stateMSP = 0
				            ints(22)=ints2(9)
							ints(23)=ints2(10)
						Case MSP_ALTITUDE
                			stateMSP = 0
                			alt = read32(ints2(5),ints2(6),ints2(7),ints2(8))
							
					End Select
				End If 
			End If 
			For quien= 0 To 3
				Dim s As String
				s=checkboxtags(quien)
				Select s
					Case "0" 'ax
						If Bit.And(ints(3),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = read16(ints(2),Bit.Not(ints(3)))-255
						Else 
							CurveVal(quien,ii)=read16(ints(2),ints(3)) 'positivo
						End If
						
					Case "1" 'ay
						If Bit.And(ints(5),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = read16(ints(4),Bit.Not(ints(5)))-255
						Else 
							CurveVal(quien,ii)=read16(ints(4),ints(5)) 'positivo
						End If 
						
					Case "2" 'az
						If Bit.And(ints(7),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = read16(ints(6),Bit.Not(ints(7)))-255
						Else 
							CurveVal(quien,ii)=read16(ints(6),ints(7)) 'positivo
						End If 
						
					Case "3" 'gx
						If Bit.And(ints(9),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = (read16(ints(8),Bit.Not(ints(9)))-255)/8
						Else 
							CurveVal(quien,ii)=(read16(ints(8),ints(9)))/8 'positivo
						End If 
					Case "4" 'gy
						If Bit.And(ints(11),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = (read16(ints(10),Bit.Not(ints(11)))-255)/8
						Else 
							CurveVal(quien,ii)=(read16(ints(10),ints(11)))/8 'positivo
						End If 
					Case "5" 'gz
						If Bit.And(ints(13),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = (read16(ints(12),Bit.Not(ints(13)))-255)/8
						Else 
							CurveVal(quien,ii)=(read16(ints(12),ints(13)))/8 'positivo
						End If 
					Case "6" 'magX
						If Bit.And(ints(15),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = (read16(ints(14),Bit.Not(ints(15)))-255)/3
						Else 
							CurveVal(quien,ii)=(read16(ints(14),ints(15)))/3 'positivo
						End If 
					Case "7" 'magY
						If Bit.And(ints(17),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = (read16(ints(16),Bit.Not(ints(17)))-255)/3
						Else 
							CurveVal(quien,ii)=(read16(ints(16),ints(17)))/3 'positivo
						End If 
					Case "8" 'magZ
						If Bit.And(ints(19),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = (read16(ints(18),Bit.Not(ints(19)))-255)/3
						Else 
							CurveVal(quien,ii)=(read16(ints(18),ints(19)))/3 'positivo
						End If 
					Case "9" 'Alt
						If Main.protocol=0 Then 
							If Bit.And(ints(21),128)=128 Then 
							 'negativo
								CurveVal(quien, ii) = (read16(ints(20),Bit.Not(ints(21)))-255)/10
							Else 
								CurveVal(quien,ii)=(read16(ints(20),ints(21)))/10 'positivo
							End If
						Else 
							CurveVal(quien,ii)=alt
						End If 
					Case "10" 'heading
						If Bit.And(ints(23),128)=128 Then 
							 'negativo
							CurveVal(quien, ii) = (read16(ints(22),Bit.Not(ints(23)))-255)
						Else 
							CurveVal(quien,ii)=(read16(ints(22),ints(23))) 'positivo
						End If 
				End Select
		
				vals(0).Text= labelcheckbox(0).Text & "= " & CurveVal(0,ii)
				vals(1).text=labelcheckbox(1).Text & "= " & CurveVal(1,ii)
				vals(2).Text=labelcheckbox(2).Text & "= " & CurveVal(2,ii)
				vals(3).Text=labelcheckbox(3).Text & "= " & CurveVal(3,ii)
			Next
		
		Else 
			If Main.protocol = 0 Then 
				Main.TextWriter1.Write("M")
				Main.TextWriter1.Flush
			Else
				
						Main.TextWriter1.Write("$M<" & Chr(MSP_RAW_IMU))
						Main.TextWriter1.Flush
						
						
						
					
			End If  
		End If
	End If
	
End Sub

Sub EraseCurves
	cvsGraph.DrawRect(rectGrid, Colors.Transparent, True, 1)
End Sub

Sub cbxDrawCurve_CheckedChange(Checked As Boolean)
	Dim cbx As CheckBox
	cbx = Sender
	Curve(cbx.Tag).Draw = Checked
End Sub

Sub labelcheckbox_Click
	Dim who As Label
	who=Sender
	i=InputList(choselist, "", who.Tag)
	If i=DialogResponse.CANCEL Then 
	Else
		checkboxtags(who.Tag)=i
		who.Text=choselist.Get(i)
	End If 
End Sub


Sub pnlCursor_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
	If Stopped = False Then
		Return
	End If
	
	Select Action
	Case Activity.ACTION_DOWN
		pnlDispValues.Visible = True
		cx = X
		If X >= 0 AND X <= GridW Then
			DrawCursor(X)
			DispValues(X)
		End If
	Case Activity.ACTION_MOVE
		If X >= 0 AND X <= GridW Then
			DrawCursor(X)
			DispValues(X)
		End If
	Case Activity.ACTION_UP
		cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
		pnlCursor.Invalidate
		pnlDispValues.Visible = False
	End Select	
	Return True
End Sub

Sub DrawCursor(x As Float)
	cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
	cx = x
	cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Red, 1)
	pnlCursor.Invalidate
End Sub

Sub DispValues(x As Int)
	Dim i As Int

	i = 100 / GridW * x
	lblValue0.Text = NumberFormat(CurveVal(0, i), 1, 6)
	lblValue1.Text = NumberFormat(CurveVal(1, i), 1, 6)
	lblValue2.Text = NumberFormat(CurveVal(2, i), 1, 6)
	lblValue3.Text = NumberFormat(CurveVal(3, i), 1, 6)
End Sub

Sub InitCurves
	Curve(0).Color = Colors.Red
	Curve(1).Color = Colors.Blue
	Curve(2).Color = Colors.Green
	Curve(3).Color = Colors.magenta

	Curve(0).Width = 1dip
	Curve(1).Width = 1dip
	Curve(2).Width = 1dip
	Curve(3).Width = 1dip
	
'	Curve(0).Scale = 1
'	Curve(1).Scale = 1
'	Curve(2).Scale = 1
'	Curve(3).Scale = 1
'	
	Curve(0).Scale = 20
	Curve(1).Scale = 20
	Curve(2).Scale = 20
	Curve(3).Scale = 20
	
	Curve(0).offset = 0
	Curve(1).offset = 0
	Curve(2).offset = 0
	Curve(3).offset = 0
	
	Curve(0).Draw = True
	Curve(1).Draw = True
	Curve(2).Draw = True
	Curve(3).Draw = True
End Sub

Sub InitCalcCurves
	w(0) = 2 * cPI * 2.1
	w(1) = 2 * cPI * 3.7
	w(2) = 2 * cPI * 4.3
	w(3) = 2 * cPI * 5.7
	
	a(0) = 1.0
	a(1) = 2.0
	a(2) = -1.0
	a(3) = 1.5
End Sub

Sub InitSpinners
	Dim i As Int
	
'	TimeScale(0) = 10
'	TimeScale(1) = 5
'	TimeScale(2) = 2
'	TimeScale(3) = 1
'	TimeScale(4) = 0.5
'	TimeScale(5) = 0.2
'	TimeScale(6) = 0.1
'	TimeScale(7) = 0.05
'	TimeScale(8) = 0.02
'	TimeScale(9) = 0.01
'
	SignalScale(0) = 1000
	SignalScale(1) = 500
	SignalScale(2) = 200
	SignalScale(3) = 100
	SignalScale(4) = 50
	SignalScale(5) = 10
	SignalScale(6) = 5
	SignalScale(7) = 2
	SignalScale(8) = 1
	SignalScale(9) = .5

	spnScale0.Initialize("spnScale")
	spnScale1.Initialize("spnScale")
	spnScale2.Initialize("spnScale")
	spnScale3.Initialize("spnScale")
	Activity.AddView(spnScale0,Activity.Width-180dip, 10%y+0*15%y,100dip,40dip)
	Activity.AddView(spnScale1,Activity.Width-180dip, 10%y+1*15%y,100dip,40dip)
	Activity.AddView(spnScale2,Activity.Width-180dip, 10%y+2*15%y,100dip,40dip)
	Activity.AddView(spnScale3,Activity.Width-180dip, 10%y+3*15%y,100dip,40dip)
	spnScale0.tag=0
	spnScale1.tag=1
	spnScale2.tag=2
	spnScale3.tag=3
	
	For i = 0 To 9
		spnScale0.Add(SignalScale(i))
		spnScale1.Add(SignalScale(i))
		spnScale2.Add(SignalScale(i))
		spnScale3.Add(SignalScale(i))
	Next
'	spnTimeScale.SelectedIndex = 6
'	
	spnScale0.SelectedIndex = 3
	spnScale1.SelectedIndex = 3
	spnScale2.SelectedIndex = 3
	spnScale3.SelectedIndex = 3
	Curve(0).Scale = Div / spnScale0.SelectedItem
	Curve(1).Scale = Div / spnScale1.SelectedItem
	Curve(2).Scale = Div / spnScale2.SelectedItem
	Curve(3).Scale = Div / spnScale3.SelectedItem
End Sub

